package club.framework.web.application.sys.resource.service.impl;


import club.framework.web.application.sys.resource.entity.Resource;
import club.framework.web.application.sys.resource.mapper.ResourceMapper;
import club.framework.web.application.sys.resource.service.IResourceService;
import club.framework.web.base.entity.BasePageReqEntity;
import club.framework.web.base.entity.BasePageResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * @date 2017/9/11.
 * @Email:sunmch@163.com
 * @author: 念梓
 * des:
 */
@Service
public class ResourceServiceImpl implements IResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public Resource getObject(Resource resource) {
        return null;
    }

    @Override
    public Resource getObject(int id) {
        return resourceMapper.getResourceById(id);
    }

    @Override
    public Resource getObject(long uid) {
        return null;
    }

    @Override
    public int save(Resource resource) {
        Date now = new Date();
        resource.setCreateTime(now);
        resource.setUpdateTime(now);
        return resourceMapper.save(resource);
    }

    @Override
    public int delete(Resource resource) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return resourceMapper.deleteResourceById(id);
    }

    @Override
    public int delete(long uid) {
        return 0;
    }

    @Override
    public int update(Resource resource) {
        return resourceMapper.update(resource);
    }

    @Override
    public BasePageResultEntity<Resource> queryPage(BasePageReqEntity<Resource> basePageReqEntity) {
        BasePageResultEntity<Resource> basePageResultEntity = new BasePageResultEntity<>();
        Resource resource = basePageReqEntity.getObj();
        int totaCount = resourceMapper.queryTotalCount(resource);
        List<Resource> resourceList = resourceMapper.queryPage(basePageReqEntity);
        basePageResultEntity.setRows(resourceList);
        basePageResultEntity.setTotal(totaCount);
        return basePageResultEntity;
    }
}
